package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YcInde;
import com.ruoyi.system.service.IYcIndeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 油厂指标管理Controller
 * 
 * @author ruoyi
 * @date 2022-10-15
 */
@RestController
@RequestMapping("/system/inde")
public class YcIndeController extends BaseController
{
    @Autowired
    private IYcIndeService ycIndeService;


    /**
     * 查询油厂指标管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:inde:list')")
    @GetMapping("/list")
    public TableDataInfo list(YcInde ycInde)
    {
        startPage();
        List<YcInde> list = ycIndeService.selectYcIndeList(ycInde);
        return getDataTable(list);
    }

    /**
     * 导出油厂指标管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:inde:export')")
    @Log(title = "油厂指标管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YcInde ycInde)
    {
        List<YcInde> list = ycIndeService.selectYcIndeListUseExport(ycInde);
        ExcelUtil<YcInde> util = new ExcelUtil<YcInde>(YcInde.class);
        util.exportExcel(response, list, "油厂指标管理数据");
    }

    /**
     * 获取油厂指标管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inde:query')")
    @GetMapping(value = "/{indeId}")
    public AjaxResult getInfo(@PathVariable("indeId") Long indeId)
    {
        return AjaxResult.success(ycIndeService.selectYcIndeByIndeId(indeId));
    }

    /**
     * 新增油厂指标管理
     */
    @PreAuthorize("@ss.hasPermi('system:inde:add')")
    @Log(title = "油厂指标管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody YcInde ycInde)
    {
        return toAjax(ycIndeService.insertYcInde(ycInde));
    }

    /**
     * 修改油厂指标管理
     */
    @PreAuthorize("@ss.hasPermi('system:inde:edit')")
    @Log(title = "油厂指标管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody YcInde ycInde)
    {
        return toAjax(ycIndeService.updateYcInde(ycInde));
    }

    /**
     * 删除油厂指标管理
     */
    @PreAuthorize("@ss.hasPermi('system:inde:remove')")
    @Log(title = "油厂指标管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{indeIds}")
    public AjaxResult remove(@PathVariable Long[] indeIds)
    {
        return toAjax(ycIndeService.deleteYcIndeByIndeIds(indeIds));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YcInde> util = new ExcelUtil<YcInde>(YcInde.class);
        util.importTemplateExcel(response, "油厂指标");
    }

    @Log(title = "油厂指标管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:inde:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YcInde> util = new ExcelUtil<YcInde>(YcInde.class);
        List<YcInde> ycIndeList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ycIndeService.importData(ycIndeList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
     * 查询指标列表
     */
    @GetMapping("/ycindeSelect")
    public AjaxResult ycindeSelect()
    {
        return AjaxResult.success(ycIndeService.selectYcIndeAll());
    }

    @GetMapping("selectYcIndeYear")
    public AjaxResult selectYcIndeYear(){
        return AjaxResult.success(ycIndeService.selectYcIndeYear());
    }

    @GetMapping("/ycindeSelectChang")
    public AjaxResult ycindeSelectChang()
    {
        return AjaxResult.success(ycIndeService.selectYcIndeChang());
    }

    @GetMapping("/ycindeSelectQu")
    public AjaxResult ycindeSelectQu()
    {
        return AjaxResult.success(ycIndeService.selectYcIndeQu());
    }

    @GetMapping("/ycindeSelectZhan")
    public AjaxResult ycindeSelectZhan()
    {
        return AjaxResult.success(ycIndeService.selectYcIndeZhan());
    }

    @GetMapping("/ycindeSelectByYear")
    public AjaxResult ycindeSelectByYear(){
        return AjaxResult.success(ycIndeService.selectYcIndeByYear());
    }



}
